{include file='common/head'}
<!--员工发布&#45;&#45;说天喊地-->
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">
    <blockquote class="layui-elem-quote layui-text">
        <div class="demoTable layui-form">
            <!--<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>-->
            <div class="demoTable layui-form">
                <div class="layui-input-inline">
                    <input type="text" placeholder="请输入员工名称" name="username" lay-verify="required|phone"  autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn " data-type="reload" ><i class="layui-icon">&#xe615;</i>搜索</button>
                <button class="layui-btn addInfo">添加</button>
            </div>
        </div>
    </blockquote>
    <div class="layui-tab" lay-filter="test">
        <ul class="layui-tab-title">
            <li lay-id="1" class="layui-this">保险公司人员</li>
            <li lay-id="2">代录人</li>
            <li lay-id="3">被保险人</li>
            <li lay-id="4">业务员</li>
            <li lay-id="5">其他人员</li>
        </ul>
        <div class="demoTable layui-for">
            <table class="layui-table" lay-data="{height: 'full-150', url:'{:url('User/getUserInfo')}',edit:true, page:true, id:'testReload',loading:true}" lay-filter="demo">
                <thead>
                <tr>
                    <th lay-data="{field:'username',width:150,fixed: true}">人员名称</th>
                    <th lay-data="{field:'mobile',width:150}">手机号码</th>
                    <th lay-data="{field:'card_num',width:180}">身份证号</th>
                    <th lay-data="{field:'company_name',sort:true,width:280}">单位</th>
                    <!--<th lay-data="{field:'company_type',sort:true,width:120,templet: '#company_type'}">单位类型</th>-->
                    <th lay-data="{field:'created_at',width:180}">添加时间</th>
                    <th lay-data="{field:'status', width:120, sort:true,templet: '#status'}">状态</th>
                    <th lay-data="{fixed: 'is_hot', width:280,fixed: 'right', align:'left', toolbar: '#barDemo'}"></th>
                </tr>
                </thead>
            </table>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="show">查看资料</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                {{# if(d.status == 0){ }}
                    <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="status" data-value="1">激活</a>
                {{# } }}
                {{# if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="status" data-value="2">审核通过</a>
                    <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="status" data-value="3">审核不通过</a>
                {{# } }}
                {{# if(d.status == 3){ }}
                <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="status" data-value="2">审核通过</a>
                {{# } }}
            </script>
            <script type="text/html" id="contentTpl" lay-event="detail_content">
                <span>{{ d.describe }}</span>
            </script>
            <script type="text/html" id="status">
                {{#  if(d.status == 1){ }}
                <span style="color: #5FB878" >待审核</span>
                {{#  }else if(d.status == 2){ }}
                <span style="color: #FF5722">审核通过</span>
                {{#  }else if(d.status == 3){ }}
                <span style="color: #d43f3a">审核不通过</span>
                {{#  }else if(d.status == 0){ }}
                <span style="color: #d43f3a">未激活</span>
                {{#  } }}
            </script>

            <script type="text/html" id="company_type">
                {{#  if(d.company_type == 1){ }}
                <span >保险公司人员</span>
                {{#  } }}
                {{#  if(d.company_type == 2){ }}
                <span >代录人</span>
                {{#  } }}
                {{#  if(d.company_type == 3){ }}
                <span >被保险人</span>
                {{#  } }}
                {{#  if(d.company_type == 4){ }}
                <span >业务员</span>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
{include file='common/footer'}
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['table','form','element'], function(){
        var table = layui.table
            ,form = layui.form
            ,element = layui.element;
        var $ = layui.$, active = {
            reload: function(){
                var username = $('input[name="username"]').val();
              //  var company_type = $('select[name="company_type"] option:checked').val();
                //执行重载
                table.reload('testReload', {
                    where: {
                        username:username,
                       // company_type:company_type,
                    }
                });
            }
        };

        element.on('tab(test)', function(elem) {
            var role_id = $(this).attr('lay-id');
            table.reload('testReload', {
                where: {
                    role_id: role_id,
                }
            });
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            //console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'show'){
                layer.open({
                    type: 2,
                    title: '查看资料',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['100%', '100%'],
                    content: '{:url("User/userShow")}?id='+data.ui_id,
                    end: function () {
                        table.reload('testReload');
                    },
                });
            }else if(obj.event === 'del'){
                layer.confirm('确定删除么', function(index){
                    $.ajax({
                        url:'{:url("User/delUser")}?id='+data.ui_id,
                        type:'get',
                        dataType:'json',
                        success:function(val){
                            if(val.code ==200){
                                obj.del();
                                layer.close(index);
                            }
                            if(val.code==500){
                                layer.msg(val.msg);
                            }
                        }
                    });

                });
            }else if(obj.event === 'status'){
                var dom = this;
                var status = $(dom).attr('data-value');
                str_msg = status == 1 ? '确定进行激活':'确定进行审核';
                layer.confirm(str_msg, function(index){
                    $.ajax({
                        url:'{:url("User/statusUser")}',
                        type:'post',
                        data:{'id':data.ui_id,'status':status},
                        dataType:'json',
                        success:function(val){
                            if(val.code ==200){
                                if(val.data.status == 1){
                                    $(dom).parent().parent().parent().find('td').eq(5).find('div').html('<span style="color: #5FB878" >待审核</span>');
                                    $(dom).parent().append('<a class="layui-btn layui-btn-info layui-btn-xs" lay-event="status" data-value="2">审核通过</a> <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="status" data-value="3">审核不通过</a>');
                                    $(dom).remove();
                                } else if(val.data.status == 2){
                                    $(dom).parent().parent().parent().find('td').eq(5).find('div').html('<span style="color: #5FB878" >审核通过</span>');
                                    $(dom).parent().html('<a class="layui-btn layui-btn-xs" lay-event="show">查看资料</a> <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>');
                                }else if(val.data.status == 3){
                                    $(dom).parent().parent().parent().find('td').eq(5).find('div').html('<span style="color: #5FB878" >审核不通过</span>');
                                    $(dom).remove();
                                }
                                layer.close(index);
                            }
                            if(val.code==500){
                                layer.msg(val.msg);
                            }
                        }
                    });

                });
            }
        });

        $('.addInfo').on('click',function(){
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['100%', '100%'],
                content: '{:url("User/userAdd")}',
                end: function () {
                    table.reload('testReload');
                },
            });
        });
    });
</script>
</body>
</html>